#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility
import re


class BMC_IPMI_007(Case):
    """
        Name:
            BMC_IPMI_007
        Label:
            获取PSU信息
        PreCondition:
            1、BMC正常运行
        TestStep:
            1.执行IPMI CMD “ipmitool raw 0x30 0x93 0xdb 0x07 0x00 0x1e 0x01 0x01 0x00 0x32“
            2. 查看ipmitool返回值，有结果A）
        ExpectedResult:
            A）PSU信息读取正确
        Parameters:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.os_host = self.device_dut.get_host(host_type=HostType.HostOS)

    # 测试步骤
    def procedure(self):
        self.log_step("1、带外执行ipmitool命令，读取PSU信息")
        psu_raw_output = self.os_host.send_combination_keys(\
            'ipmitool raw 0x30 0x93 0xdb 0x07 0x00 0x1e 0x01 0x01 0x00 0x32', timeout=3)
        if re.search("48 55 41 57 45 49", psu_raw_output):
            self.log_info("读取PSU厂商信息正确")
        else:
            raise Exception("读取PSU厂商信息失败")

    # 测试结束后恢复环境
    def post_test_case(self):
        pass